package ui;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import util.Java_JDBC;

import listener.ClassIPListener;
import listener.LoginListener;
import listener.QuestionNumberListener;

import config.Config;
import config.SocketConfig;

public class QuestionNumberUI extends JFrame {
	public JTextField singleStart;// 单选题目开始编号
	public JTextField singleEnd;// 单选题目结束编号
	public JTextField multipleStart;// 多选题目开始编号
	public JTextField multipleEnd;// 多选题目结束编号
	public JTextField digitalStart;// 数字题目开始编号
	public JTextField digitalEnd;// 数字题目结束编号
//	public JTextField paperName;//试卷名称
	
	JLabel jLabel1, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, jLabel7;
	JPanel jp1, jp2, jp3, jp4, jp5, jp6;
	public JButton jb1, jb2,jb3; // 创建按钮
	public JComboBox<Object> ca;

	public QuestionNumberUI() throws Exception{
		jLabel1 = new JLabel("单选题目开始编号: ");
		jLabel2 = new JLabel("单选题目结束编号: ");
		singleStart = new JTextField(12);
		singleEnd = new JTextField(12);
		singleStart.setText("1");
		singleEnd.setText("10");
		
		jLabel3 = new JLabel("多选题目开始编号: ");
		jLabel4 = new JLabel("多选题目结束编号: ");
		multipleStart = new JTextField(12);
		multipleEnd = new JTextField(12);
		multipleStart.setText("11");
		multipleEnd.setText("20");
		
		jLabel5 = new JLabel("数字题目开始编号: ");
		jLabel6 = new JLabel("数字题目结束编号: ");
		digitalStart = new JTextField(12);
		digitalEnd = new JTextField(12);
		digitalStart.setText("21");
		digitalEnd.setText("30");
		
		jLabel7 = new JLabel("请选择试卷名称: ");
//		paperName = new JTextField(12);
		List<String> paperList = new Java_JDBC().searchPaperName();
		ca = new JComboBox<Object>(paperList.toArray());
		ca.setBounds(230, 0, 140, 30);
		ca.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Config.paperName = (String) ca.getSelectedItem();
				System.out.println("Config.paperName:  "+Config.paperName);
			}
		});
		ca.setSelectedIndex(0);
		
		jb1 = new JButton("确认");
		jb2 = new JButton("取消");
		jb3 = new JButton("打开试卷");
		
		jp1 = new JPanel();
		jp2 = new JPanel();
		jp3 = new JPanel();
		jp4 = new JPanel();
		jp5 = new JPanel();
		jp6 = new JPanel();

		// 设置布局
		this.setLayout(new GridLayout(4, 1));
		jp4.setLayout(new GridLayout(2, 1));
			
		// 第一块面板添加用户名和文本框
		jp1.add(jLabel1);
		jp1.add(singleStart);
		jp1.add(jLabel2);
		jp1.add(singleEnd);
		
		// 第二块面板添加用户名和文本框
		jp2.add(jLabel3);
		jp2.add(multipleStart);
		jp2.add(jLabel4);
		jp2.add(multipleEnd);

		jp3.add(jLabel5);
		jp3.add(digitalStart);
		jp3.add(jLabel6);
		jp3.add(digitalEnd);
		
		jp5.add(jLabel7);
		jp5.add(ca);
		jp6.add(jb1);
		jp6.add(jb2); // 第三块面板添加确认和取消
		jp6.add(jb3);
		jp4.add(jp5);
		jp4.add(jp6);
		
		QuestionNumberListener listener = new QuestionNumberListener(this);
		jb1.addActionListener(listener);
		jb2.addActionListener(listener);
		jb3.addActionListener(listener);
		this.add(jp1);
		this.add(jp2);
		this.add(jp3); 
		this.add(jp4);
		// 设置显示
		this.setSize(300, 500);
//		this.setDefaultCloseOperation(3);
		this.setLocationRelativeTo(null);
		this.setTitle("题目编号设置");
	}
	
//	public static void main(String[] args) throws Exception{
//		new QuestionNumberUI().setVisible(true);
//	}
	
}
